//
//  MCAnalyzedResult.h
//  iMooc
//
//  Created by CoderXSLee on 13/6/3.
//  Copyright © 2013年 李雪松. All rights reserved.
//

#import <Foundation/Foundation.h>

/// 通用结果码
typedef NS_ENUM(NSInteger, MCResultCode) {
    /// 成功为空
    MC_RESULT_EMPTY = 20002,
    /// 请求成功
    MC_RESULT_SUCCESS = 20000,
    /// 请求失败
    MC_RESULT_FAILURE = 400,
    /// 网络异常/无网络/网络丢失等
    MCNetworkAbnormal = 1009,
    /// 其他错误
    MCErrorTip = 23456,
};

@interface MCCommonResult : NSObject

/// 结果码
@property (nonatomic, assign) MCResultCode resultCode;

/// 结果描述
@property (nonatomic, strong) NSString *resultDesc;

/// 请求
@property (nonatomic, strong) NSURLRequest *request;

/** 解析服务器返回的json中 code 和 msg 以及 data
 该项可以在此 setResponseObjectCodeKey:msgKey:dataKey:中设置key
 如 [[MCNetworking sharedInstance] setResponseObjectCodeKey:@"code" msgKey:@"msg" dataKey:@"data"];
 则服务器返回JSON应该为:
                 {
                    "code":200,
                    "msg":"请求成功",
                    "data":"此处是服务返回的数据可以是对象、字典、数组、字典数组、等"
                 }
 */
+ (instancetype)resultWithResponse:(id)response request:(NSURLRequest *)request;
+ (instancetype)resultWithCode:(NSInteger)code desc:(NSString *)desc;
+ (instancetype)resultWithCode:(NSInteger)code desc:(NSString *)desc request:(NSURLRequest *)request;

@end




/// 业务层结果类
@interface MCAnalyzedResult : MCCommonResult

/**
 *  判断结果码是否面向用户
 *
 *  @return YES-面向用户 NO-内部消化
 */
- (BOOL)isExposedToUser;

/**
 *  判断指定结果码是否面向用户
 *
 *  @param resultCode 结果码
 *
 *  @return YES-面向用户 NO-内部消化
 */
- (BOOL)isExposedToUser:(NSInteger)resultCode;

/**
 *  显示当前的结果描述
 */
- (void)show;

/**
 *  显示指定的结果描述
 *
 *  @param resultDesc 结果描述信息
 */
- (void)show:(NSString *)resultDesc;

@end
